<%
'#################################################################################
'## UnWritten Open Source Blog Engine
'#################################################################################
'## Copyright (C) 2008 Luigi Violin
'##
'## This program is free software: you can redistribute it and/or modify
'## it under the terms of the GNU General Public License as published by
'## the Free Software Foundation, either version 2 of the License, or
'## (at your option) any later version.
'##
'## This program is distributed in the hope that it will be useful,
'## but WITHOUT ANY WARRANTY; without even the implied warranty of
'## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'## GNU General Public License for more details.
'##
'## You should have received a copy of the GNU General Public License
'## along with this program.  If not, see <http://www.gnu.org/licenses/>.
'##
'## You can obtain support from our forums at:
'##     <http://www.unwrittenblog.com/forums/>
'## Contact the author directly:
'##     <zaamit@hotmail.com/>
'##
'#################################################################################
%>
<!--#include file="check-login.asp"-->
<!--#include file="header.asp"-->
<!--#include file="sidebar.asp"-->

<%
Dim wktitle,wkcontent,wktags,wkicon,wkpublish_status, system_page
wktitle = ""
wkcontent = ""
wktags = ""
wkicon = ""
wkpublish_status = 1
wkaction = 1
wktype = 1
wktags = ""
if request.QueryString("id") <> "" then
dbRS1.open "select * from " & db_prefix & "posts where id = " & request.QueryString("id"),dbConn
wktitle = dbRS1("title")
wkcontent = dbRS1("content")
wkicon = dbRS1("icon")
wkpublish_status = dbRS1("publish_status")
wkaction = 2
wktype = dbRS1("ent_type")
if wktype = 2 then
	'article category
	wktags = dbRS1("category")
	else
	'post tags
		dbRS1.close
		dbRS1.open "select * from " & db_prefix & "posttags," & db_prefix & "tags where " & db_prefix & "tags.id = " & db_prefix & "posttags.tagid and postid = " & request.QueryString("id"),dbConn
		do while not dbRS1.eof
			wktags = wktags & dbRS1("text") & ", "
			dbRS1.movenext
		loop
		if len(wktags)>0 then wktags = left(wktags,len(wktags)-2)
end if
dbRS1.close
end if
if request.QueryString("type") <> "" then wktype = cint(request.QueryString("type"))
'system pages
if lcase(wktitle) = "about" or lcase(wktitle) = "contact" or lcase(wktitle) = "home" then system_page = true
%>

<!-- TinyMCE -->
<script type="text/javascript" src="/includes/modules/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		skin : "o2k7",
		skin_variant : "black",
		plugins : "safari,pagebreak,style,layer,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		// Theme options
		theme_advanced_buttons1 : ",bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontsizeselect,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,advhr",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js"

	});
</script>
<!-- /TinyMCE -->

<div id="main">
	<div id="inner">
<%
	if request.QueryString("s") <> ""then
		Response.Write(request.QueryString("s"))
	end if
%>
<form id="edit_post" method="post" action="doedit.asp">
<strong>Type</strong> <input type="radio" name="type" value="1" <%if wktype=1 then Response.Write "checked=""checked"""%> <%if system_page then response.Write " disabled=""disabled"" "%> onclick="document.location.href='edit.asp?id=<%=request.QueryString("id")%>&type=1'" />Post &nbsp;<input type="radio" name="type" value="2" <%if wktype=2 then Response.Write "checked=""checked"""%> <%if system_page then response.Write " disabled=""disabled"" "%> onclick="document.location.href='edit.asp?id=<%=request.QueryString("id")%>&type=2'" />Article
<%if system_page then response.Write " <input type=""hidden"" name=""type"" value=""2"">"%>
<%=sep1%>
<strong>Title</strong> <input type="text" size="107" maxlength="250" id="title" name="title" value="<%=wktitle%>" <%if system_page then response.Write " readonly=""readonly"" "%> />
<%=sep1%>
<textarea id="content" name="content"><%=server.HTMLEncode(wkcontent)%></textarea>
<%=sep1%>
<% if wktype <> 2 then %>
<strong>Tags</strong> &nbsp;<input type="text" size="107" maxlength="249" id="tags" name="tags" value="<%=wktags%>" /><br />
<span class="small">Comma separated. Example: <i>news, hobby, diy</i></span>
<%=sep1%>
<strong>Icon</strong><%=FR%> &nbsp;<input type="text" size="107" maxlength="249" id="icon" name="icon" value="<%=wkicon%>" disabled="disabled" /><br />
<span class="small">An image to identify your article or post (optional).</span>
<%=sep1%>
<% else %>
<strong>Category</strong><br />
<input type="radio" onclick="document.getElementById('stag').disabled=false;document.getElementById('itag').disabled=true;" name="rtag" checked="checked" /><span class="small"> Pick one </span>
<select name="tags" id="stag">
<%
'grab list of categories from db
dbRS3.open "select category from " & db_prefix & "posts where ent_type = 2 group by category order by category",dbConn
do while not dbRS3.eof
	if dbRS3("category") <> "" then
		Response.Write "<option value=""" & dbRS3("category") & """"
		if wktags = dbRS3("category") then response.Write " selected "
		Response.Write ">" & dbRS3("category") & "</option>"
		else
			Response.Write "<option value=""Uncategorized"">Uncategorized</option>"
	end if
	dbRS3.movenext
loop
dbRS3.close
%>
<select>
<strong>OR</strong>
<input type="radio" onclick="document.getElementById('stag').disabled=true;document.getElementById('itag').disabled=false;" name="rtag" />
<span class="small"> insert new </span>
<input type="text" size="20" maxlength="50" id="itag" name="tags" disabled="disabled" /><br />
<%=sep1%>
<% end if %>
<strong>Publish Status</strong> <input type="radio" name="publish_status" value="1" <%if wkpublish_status = 1 then Response.Write "checked=""checked"""%> />Public &nbsp;&nbsp;<input type="radio" name="publish_status" id="publish_status" value="2" <%if wkpublish_status = 2 then Response.Write "checked=""checked"""%> />Private &nbsp;&nbsp;<input type="radio" name="publish_status" value="0" <%if wkpublish_status = 0 then Response.Write "checked=""checked"""%> />Unpublished
<%=sep1%>
<div class="form_buttons">
<input type="hidden" name="id" value="<%=request.QueryString("id")%>" />
<input type="hidden" name="action" value="<%=wkaction%>" />
<input type="submit" value="Save" class="big_button" />
</div>
</form>
<!-- /main inner --></div><!-- /main --></div>

<!--#include file="footer.asp"-->